package com.tz.actions.book;

import com.opensymphony.xwork2.ActionSupport;
import com.tz.entity.Page;
import com.tz.service.IBookService;
import com.tz.util.MyAcUtil;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

/**
 * Created by heziqian on 2016/10/21.
 */
@Namespace("/")
public class CategoryAction extends ActionSupport{

    Page page;
    private IBookService bookService =
            MyAcUtil.getInstance().getBean(IBookService.class);


    @Action(value = "category",
            results = {@Result(location="/category.jsp"),
                    @Result(name = "input",location = "/cart.jsp")
            })
    public String execute2() {



        if(page==null){
            page = bookService.findBookByPage(null,1,6);
        }else {

            int pageNow = page.getPageNow();
            int pageSize = page.getPageSize();
            pageNow=pageNow==0?1:pageNow;
            pageSize=pageSize==0?6:pageSize;

            page = bookService.findBookByPage(null,
                    pageNow, pageSize);
        }

        return SUCCESS;


    }

    public Page getPage() {
        return page;
    }

    public void setPage(Page page) {
        this.page = page;
    }
}
